exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  constructor(ctx) {
    super(ctx);
    this.MenuService = think.service('sys/MenuService');
  }
  indexAction() {}
  /**
     * 新增/修改菜单
     *
     * @returns
     */
  doAddOrUpdateAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      // console.log(this.post());
      const PostData = _this.post('id,menu_level,menu_name,menu_order,menu_url,comp_path,parent_id,menu_type,menu_i' + 'con,menu_source,is_show,is_button,is_crumb,href,permission,parent,parent_ids');
      const res = yield _this.MenuService.doAddOrUpdate(PostData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this.json(aj);
    })();
  }
  /**
     * 查询菜单信息  （分页）
     *
     * @returns
     */
  doQueryMenuListAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const GetData = _this2.get('page,pageSize,menu_name');
      const res = yield _this2.MenuService.getSysMenuList(GetData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this2.json(aj);
    })();
  }

  /**
     * 删除菜单
     *
     * @returns
     */
  delSysMenuInfoAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const postData = {
        id: _this3.post('id')
      };
      const res = yield _this3.MenuService.delSysMenuInfo(postData);
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this3.json(aj);
    })();
  }

  /**
     * 查询菜单信息 全部
     *
     * @returns
     */
  doQueryMenuAllAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const res = yield _this4.MenuService.getAllMenu();
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this4.json(aj);
    })();
  }

  /**
     * 查询父级菜单
     *
     * @returns
     */
  doQueryMenuLevelAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const res = yield _this5.MenuService.getsysMenuLevel(_this5.get());
      if (!res.error) {
        aj.success = res.success;
        aj.msg = res.msg;
        aj.result = res.result;
      } else {
        aj.success = false;
        aj.msg = `查询失败:${res.error}`;
      }
      return _this5.json(aj);
    })();
  }
  getMenuListByAction() {
    var _this6 = this;

    return _asyncToGenerator(function* () {
      // 条件查询菜单信息
      const getData = _this6.get();
      const res = yield _this6.MenuService.getSysMenuList(getData);
      return _this6.json(res);
    })();
  }

  getMenuListByidAction() {
    var _this7 = this;

    return _asyncToGenerator(function* () {
      // 条件查询菜单信息
      const aj = think.ajaxJson();
      const getData = {
        id: _this7.get('id')
      };
      const res = yield _this7.MenuService.getSysMenuListById(getData);

      if (res && res.error) {
        aj.success = false;
        aj.msg = '获取失败';
      } else {
        aj.result = res;
      }
      return _this7.json(aj);
    })();
  }
  getMenuListByIdsAction() {
    var _this8 = this;

    return _asyncToGenerator(function* () {
      // 条件查询菜单信息
      const aj = think.ajaxJson();
      const getData = _this8.get('ids,id,page,pageSize');
      const res = yield _this8.MenuService.getSysMenuListByIds(getData);

      if (res && res.error) {
        aj.success = false;
        aj.msg = '获取失败';
      } else {
        aj.result = res;
      }
      return _this8.json(aj);
    })();
  }
};